﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Diagnostics;

namespace EAEcoreAddin.SQLWrapperClasses
{
    /*
     *Created by Alexander Schleich
     *for EMoflon:
     *http://www.moflon.org/emoflon/
     */
    class EACollection :  EA.Collection
    {
        ArrayList collection = new ArrayList();
        #region IDualCollection Members

        public object AddNew(Object newEntry)
        {
            collection.Add(newEntry);
            return newEntry;
        }
        public short Count
        {
            get 
            {
                return (short)collection.Count;
            }
        }

        public void Delete(short index)
        {
            collection.RemoveAt(index);
        }

        public void DeleteAt(short index, bool Refresh)
        {
            throw new NotImplementedException();
        }

        [DebuggerHidden]
        public object GetAt(short index)
        {
            if(collection.Count > 0)
                return collection[index];
            return null;
        }

        public object GetByName(string Name)
        {
            foreach (Object actObject in this.collection)
            {
                if (actObject is EA.TaggedValue)
                {
                    EA.TaggedValue tag = actObject as EA.TaggedValue;
                    if (tag.Name == Name)
                        return tag;
                }
                else if (actObject is EA.ConnectorTag)
                {
                    EA.ConnectorTag tag = actObject as EA.ConnectorTag;
                    if (tag.Name == Name)
                        return tag;
                }
                else if (actObject is EA.MethodTag)
                {
                    EA.MethodTag tag = actObject as EA.MethodTag;
                    if (tag.Name == Name)
                        return tag;
                }
            }
            return null;
        }

        public System.Collections.IEnumerator GetEnumerator()
        {
            return new IEnumeratorImpl(collection);
        }

        public string GetLastError()
        {
            throw new NotImplementedException();
        }

        public EA.ObjectType ObjectType
        {
            get { throw new NotImplementedException(); }
        }

        public void Refresh()
        {
            return;
        }

        #endregion

        #region IDualCollection Members

        public object AddNew(string Name, string Type)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
